<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet"/>
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/Widget/zTree/css/zTreeStyle/zTreeStyle.css}" type="text/css">

    <!--[if IE 7]>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome-ie7.min.css}"/>
    <![endif]-->
    <!--[if lte IE 8]>
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace-ie.min.css}"/>
    <![endif]-->
    <script th:src="@{/erp/js/jquery-1.9.1.min.js}"></script>
    <script th:src="@{/erp/assets/js/bootstrap.min.js}"></script>
    <script th:src="@{/erp/assets/js/typeahead-bs2.min.js}"></script>
    <!-- page specific plugin scripts -->
    <script th:src="@{/erp/assets/js/jquery.dataTables.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.bootstrap.js}"></script>
    <script type="text/javascript" th:src="@{/erp/js/H-ui.js}"></script>
    <script type="text/javascript" th:src="@{/erp/js/H-ui.admin.js}"></script>
    <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript"></script>
    <script th:src="@{/erp/assets/laydate/laydate.js}" type="text/javascript"></script>
    <script type="text/javascript" th:src="@{/erp/Widget/zTree/js/jquery.ztree.all-3.5.min.js}"></script>
    <script th:src="@{/erp/js/lrtk.js}" type="text/javascript"></script>
    <title>打码任务分配</title>

</head>

<body>

<div class="margin clearfix">
    <div class="stystems_style">
        <div class="tabbable">
            <div class="page-content clearfix">
                <div id="Member_Ratings">
                    <div class="d_Confirm_Order_style">
                        <ul class="nav nav-tabs" id="myTab">
                            <li class="active">
                                <a data-toggle="tab" href="#home"><i class="green fa fa-home bigger-110"></i>打码任务分配</a>
                            </li>
                        </ul>
                    </div>

                    <div class="tab-content">

                        <div id="home" class="tab-pane active">
                            <div class="search_style">
                                <form>
                                <ul class="search_content clearfix">
                                    <li><label class="l_f">激光码查询：</label><input name="nocode" type="text" class="text_add"
                                                                                placeholder="输入订单编号或激光码"
                                                                                style=" width:400px"/></li>
                                    <li style="width:90px;">
                                        <button type="button" class="btn_search" id="search"><i class="icon-search"></i>查询</button>
                                    </li>
                                </ul>
                                </form>
                            </div>

                            <!---->
                            <div class="border clearfix">

        <span class="l_f">
        <a href="javascript:;" onclick="member_zd()" class="btn btn-info">自动分配</a>
		<a href="javascript:;" id="member_add" class="btn btn-success">手动分配</a>
		<a href="javascript:;" class="btn btn-danger" id="delete"><i class="icon-trash"></i>批量删除</a>
		</span>
                            </div>
                            <table class="table table-striped table-bordered table-hover" id="sample-table">
                                <thead>
                                <tr>
                                    <th width="30"><label ><input  type="checkbox" id="btnAllChk" class="ace" ><span
                                            class="lbl"></span></label></th>
                                    <th width="170">订单编号</th>
                                    <th width="170">组码</th>
                                    <th width="170">状态</th>
                                    <th width="100">打印机</th>
                                </tr>
                                </thead>
                                <tbody>


                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!--手动分配图层-->
                    <div class="add_menber" id="add_menber_style" style="display:none">

                        <ul class=" page-content">
                            <table class="table table-striped table-bordered table-hover" id="sample-table1">
                                <thead>
                                <tr>
                                    <th width="10"></th>
                                    <th width="150">打印机编号</th>
                                    <th width="80">服务器</th>
                                    <th width="150">描述</th>
                                    <th width="120">IP地址</th>
                                </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                        </ul>
                    </div>
                    <!--编辑图层-->
                    <div class="add_menbe" id="add_menber_styl" style="display:none">

                        <ul class=" page-content">
                            <li><label class="label_name" style="width:100px">打印数量：</label><span class="add_name"><input
                                    name="服务器" type="text" class="text_add"/></span>

                                <div class="prompt r_f"></div>
                            </li>
                            <br/>
                            <li><label class="label_name">状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态：</label><span
                                    class="add_name">
     <label><input name="form-field-radio1" type="radio" checked="checked" class="ace"><span
             class="lbl">已打印</span></label>&nbsp;&nbsp;&nbsp;
     <label><input name="form-field-radio1" type="radio" class="ace"><span class="lbl">待打印</span></label></span>

                                <div class="prompt r_f"></div>
                            </li>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script>
    $(function () {
        var table = $('#sample-table').dataTable({
            "autoWidth": false,//当重复刷新表格时，我的页面会出现变形的，现象，加了这个就好了
            searching: false,
            serverSide: true,   //开始服务器分页
            destroy:true,
            ajax: {
                url: '/laser/findfp',
                type: 'get',
                data: function (d) {
                    var data = $('form').serialize();   //获取查询条件

                    //获取分页信息
                    var searchParams = {
                        start: d.start,
                        length: d.length,
                    };
                    data = data + '&' + $.param(searchParams);
                    return data;
                }
            },
            columnDefs: [{"defaultContent": "",
                "targets": "_all"}],
            columns: [
                {"data": "id", "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append('<label><input type="checkbox" value="' + rowData.id + '" name="yy"  class="ace"><span\n' +
                            '                                            class="lbl"></span></label>');
                    }
                },
                {"data": "l_no"},
                {"data": "l_code"},
                {"data": "l_status", "createdCell": function (td, cellData, rowData, row, col) {
                        console.log(cellData)
                        if (cellData == "1") {
                            $(td).empty().append("已打印");
                        } else if (cellData == "-1") {
                            $(td).empty().append('未打印');
                        }
                    }
                },
                 {"data": "l_printer"},

            ]
        });
        //搜索按钮事件
        $('#search').click(function () {
            table.fnUpdate();
        })

    })



        $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                    .each(function () {
                        this.checked = that.checked;
                        $(this).closest('tr').toggleClass('selected');
                    });

        });





    /*自动分配跳转*/
    function member_zd(id) {

            var ids = "" ;

         $("input[name='yy']:checked").each(function (i) {    //把所有被选中的复选框的值存入数组
           ids += $(this).val()+",";
         });
            var ids1 =  ids.substr(0,ids.length-1);
             console.log(ids1);
         if (ids1=="") {
            layer.open({
                title: '提示',
                content: '请选择需要自动分配的订单编号！'
            })
            return;
        }else {

          if($("input[name=yy]:checked").parent().parent().next().next().next().text().indexOf("已打印")!=-1){


                 alert("存在已完成打印的订单")
               return;
          }
             window.location.href="/laser/zd?ids="+ids1;


         }






    }
    /*打印机-手动分配*/
    $('#member_add').on('click', function () {

        var abc = [];
        var abcd = [];
        //定义一个空数组
        $("input[name='yy']:checked").each(function (i) {    //把所有被选中的复选框的值存入数组
            abc[i] = $(this).val();
        });


        if (abc.length<1) {
            layer.open({
                title: '提示',
                content: '请选择需要手动分配的订单编号！'
            })
            return;
        }

        if($("input[name=yy]:checked").parent().parent().next().next().next().text().indexOf("已打印")!=-1){


            alert("存在已完成打印的订单")
            return;
        }

        var table = $('#sample-table1').dataTable({
            destroy:true,
            "autoWidth":false,
            searching: false,
            serverSide: true,   //开始服务器分页


            ajax: {
                url:'/laser/findprinter',
                type: 'post',
                data: function (d) {
                    var searchParams = {
                        start: d.start,
                        length: d.length,
                    };
                    return $.param(searchParams);
                }
            },
            columns: [
                {"data": "id", "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append('<label><input type="checkbox" value="' + rowData.id + '" id="ID" name="as"  class="ace"><span\n' +
                            '                                            class="lbl"></span></label>');
                    }
                },
                {"data": "p_num"},
                {"data": "p_server"},
                {"data": "p_describe"},
                  {"data": "p_ip"},
            ]
        });



        layer.open({

            type: 1,
            title: '手动分配打印机',
            maxmin: true,
            shadeClose: true, //点击遮罩关闭层
            area: ['800px', ''],
            content: $('#add_menber_style'),
            btn: ['开始打印', '取消'],
            yes: function (index, layero) {
                var num = 0;
                var str = "";

                $(".add_menber input[type$='text']").each(function (n) {
                    if ($(this).val() == "") {

                        layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                            title: '提示框',
                            icon: 0,
                        });
                        num++;
                        return false;
                    }
                });
                if (num > 0) {
                    return false;
                }
                else {
                    $("input[name='as']:checked").each(function (i) {    //把所有被选中的复选框的值存入数组
                        abcd[i] = $(this).val();
                    });


                    window.location.href="/laser/dayin?id1="+abc+"&id2="+abcd


                    layer.alert('您的打印任务已经提交给打印机，请查看打印情况，谢谢！', {
                        title: '提示框',
                        icon: 1,
                    });
                    layer.close(index);
                }
            }
        });
    });



    $(function () {

        //全不选

        $("#btnAllNotChk").click(function () {

            $("#chk input:checkbox").removeAttr("checked");

        });

        //全选

        $("#btnAllChk").click(function () {

            $(".ace").attr("checked", "checked");

        });

        //反选

        $("#btnInvert").click(function () {

            $("#chk input:checkbox").each(function () {

                this.checked = !this.checked;

            })
        });
    })



    $("#delete").click(function () {
        var abc = $("input[type=checkbox]:not(:eq(0)):checked");
        var arr = [];
        for (var i = 0; i < abc.length; i++) {
             arr.push(abc[i].value);
        }
        console.log(arr)
        $.ajax({
            url:'/laser/deletecode',
            type:'post',
            dataType:'json',
            contentType : "application/json;charsetset=UTF-8",
            data : JSON.stringify(arr),
            success:function (data) {
                if (data.rs){

                }else {
                    layer.msg(data.msg, {icon: 2, time: 2000});
                }
            }
         })
         window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
    })

</script>
